#include  <string>
#include  <iostream>
#include  <algorithm>
#include  <vector>
using namespace std;


int main(int argc, char *argv[])
{
	string a,b;
	cin >> a >> b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	vector<int> _a,_b;
	int i = 1, sum = 1,len = a.size();
	while( i < len )
	{
		if(i == len - 1)
		{
			if(a[i] == a[i-1])
			{
				sum++;
				_a.push_back(sum);
			}
			else
			{
				_a.push_back(sum);
				_a.push_back(1);
			}
			break;
		}
		if( a[i] == a[i-1] )
			sum++;
		else
		{
			_a.push_back(sum);
			sum = 1;
		}
		++i;
	}
	i = 1;
	sum = 1;
	while( i < len )
	{
		if(i == len - 1)
		{
			if(b[i] == b[i-1])
			{
				sum++;
				_b.push_back(sum);
			}
			else
			{
				_b.push_back(sum);
				_b.push_back(1);
			}
			break;
		}
		if( b[i] == b[i-1] )
			sum++;
		else
		{
			_b.push_back(sum);
			sum = 1;
		}
		++i;
	}
	sort(_a.begin(),_a.end());
	sort(_b.begin(),_b.end());
	if(_a==_b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
